package com.hamishmedlin.psxpw;

import java.util.HashMap;
import java.util.Map;

public class FormData {

	private int nextmap = 1;
	private int gameskill = 0;
	private Map<String,Boolean> checked;
	private int clip = 50;
	private int shell = 0;
	private int cell = 0;
	private int misl = 0;
	private int health = 100;
	private int armorpoints = 0;
	private int armortype = 0;
	
	
	public FormData(){
		checked = new HashMap<String,Boolean>();
		for(String weapon : QGlobals.weaponControlForIndex){
			checked.put(weapon, false);
		}
		
		checked.put(QGlobals.WEAPON_FIST, true);
		checked.put(QGlobals.WEAPON_PISTOL, true);
		checked.put(QGlobals.BACKPACK, false);
	}
	
	public void setHealth(int health){		
		if(health < 1 || health > 200){
			throw new IllegalArgumentException("Health can't be less than 1 or greater than 200");
		}
		this.health = health;
	}
	
	public int getHealth(){
		return health;
	}
	
	public void setArmor(int armor){		
		if(armor < 0 || armor > 200){
			throw new IllegalArgumentException("Armor can't be less than 0 or greater than 200");
		}
		this.armorpoints = armor;
	}
	
	public int getArmor(){
		return armorpoints;
	}
	
	public void setShell(int shell){
		if(shell < 0){
			throw new IllegalArgumentException("Can't have less that 0 ammo");
		}
		
		this.shell = shell;
		if(checked.get(QGlobals.BACKPACK)){
			if(shell > 100){
				this.shell = 100;
			}
		}else{
			if(shell > 50){
				this.shell = 50;
			}
		}
	}
	
	public int getShell(){
		return shell;
	}
	
	public void setCell(int cell){
		if(cell < 0){
			throw new IllegalArgumentException("Can't have less that 0 ammo");
		}
		
		this.cell = cell;
		if(checked.get(QGlobals.BACKPACK)){
			if(cell > 600){
				this.cell = 600;
			}
		}else{
			if(cell > 300){
				this.cell = 300;
			}
		}
	}
	
	public int getCell(){
		return cell;
	}
	
	public void setRockets(int misl){
		if(misl < 0){
			throw new IllegalArgumentException("Can't have less that 0 ammo");
		}
		
		this.misl = misl;
		if(checked.get(QGlobals.BACKPACK)){
			if(misl > 100){
				this.misl = 100;
			}
		}else{
			if(misl > 50){
				this.misl = 50;
			}
		}
	}
	
	public int getRockets(){
		return misl;
	}
	
	public void setClip(int clip){
		if(clip < 0){
			throw new IllegalArgumentException("Can't have less that 0 ammo");
		}
		
		this.clip = clip;
		
		if(checked.get(QGlobals.BACKPACK)){
			if(clip > 400){
				this.clip = 400;
			}
		}else{
			if(clip > 200){
				this.clip = 200;
			}
		}
	}
	
	public int getClip(){
		return clip;
	}
	
	public void setNextMap(int level){
		if(level < 1 || level > 59){
			throw new IllegalArgumentException("Level can't be less than 1 or greater than 59");
		}
		
		nextmap = level;
	}
	
	public int getNextMap(){
		return nextmap;
	}
	
	public void setGameSkil(int skill){
		if(skill < 0 || skill > 3){
			throw new IllegalArgumentException("Skill can't be less than 0 or greater than 3");
		}
		
		gameskill = skill;
	}
	
	public int getGameSkill(){
		return gameskill;
	}
	
	public void setArmorType(int armor){
		if(armor < 0 || armor > 2){
			throw new IllegalArgumentException("Armor type can't be less than 0 or greater than 2");
		}
		
		armortype = armor;
	}
	
	public int getArmorType(){
		return armortype;
	}
	
	public void setChecked(String key,boolean checked){
		if(!this.checked.containsKey(key)){
			throw new IllegalArgumentException("Invalid checked key. " + key);
		}
		this.checked.put(key, checked);
	}
	
	public boolean getChecked(String key){
		if(!checked.containsKey(key)){
			throw new IllegalArgumentException("Invalid checked key. " + key);
		}
		return checked.get(key);
	}
	
	public int getMaxAmmo(String type){
		for(int i = 0; i < QGlobals.maxAmmoCtrlForIdx.length;i++){
			if(!QGlobals.maxAmmoCtrlForIdx[i].equals(type)){
				continue;
			}
			
			if(checked.get(QGlobals.BACKPACK)){
				return QGlobals.backMaxAmmo[i];
			}else{
				return QGlobals.normMaxAmmo[i];
			}
		}
		
		throw new IllegalArgumentException("Invalid max ammo type. " + type);
	}
	
	
	
	
}
